home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / hmac.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  2KB  |  76 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4.  
  5. def _strxor(s1, s2):
  6.     return ''.join(map((lambda x, y: chr(ord(x) ^ ord(y))), s1, s2))
  7.  
  8. digest_size = None
  9. _secret_backdoor_key = []
  10.  
  11. class HMAC:
  12.     
  13.     def __init__(self, key, msg = None, digestmod = None):
  14.         if key is _secret_backdoor_key:
  15.             return None
  16.         
  17.         if digestmod is None:
  18.             import hashlib as hashlib
  19.             digestmod = hashlib.md5
  20.         
  21.         if callable(digestmod):
  22.             self.digest_cons = digestmod
  23.         else:
  24.             
  25.             self.digest_cons = lambda d = ('',): digestmod.new(d)
  26.         self.outer = self.digest_cons()
  27.         self.inner = self.digest_cons()
  28.         self.digest_size = self.inner.digest_size
  29.         if hasattr(self.inner, 'block_size'):
  30.             blocksize = self.inner.block_size
  31.             if blocksize < 16:
  32.                 blocksize = 64
  33.             
  34.         else:
  35.             blocksize = 64
  36.         ipad = '6' * blocksize
  37.         opad = '\\' * blocksize
  38.         if len(key) > blocksize:
  39.             key = self.digest_cons(key).digest()
  40.         
  41.         key = key + chr(0) * (blocksize - len(key))
  42.         self.outer.update(_strxor(key, opad))
  43.         self.inner.update(_strxor(key, ipad))
  44.         if msg is not None:
  45.             self.update(msg)
  46.         
  47.  
  48.     
  49.     def update(self, msg):
  50.         self.inner.update(msg)
  51.  
  52.     
  53.     def copy(self):
  54.         other = HMAC(_secret_backdoor_key)
  55.         other.digest_cons = self.digest_cons
  56.         other.digest_size = self.digest_size
  57.         other.inner = self.inner.copy()
  58.         other.outer = self.outer.copy()
  59.         return other
  60.  
  61.     
  62.     def digest(self):
  63.         h = self.outer.copy()
  64.         h.update(self.inner.digest())
  65.         return h.digest()
  66.  
  67.     
  68.     def hexdigest(self):
  69.         return []([ hex(ord(x))[2:].zfill(2) for x in tuple(self.digest()) ])
  70.  
  71.  
  72.  
  73. def new(key, msg = None, digestmod = None):
  74.     return HMAC(key, msg, digestmod)
  75.  
  76.